<include file="public/header"/>
<link rel="stylesheet" href="__ADMIN__/css/global.css">
<style>
    .layui-table-cell {
        height:inherit !important;
    }
</style>
</head>
<body style="background: #fff;">
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <form class="layui-form">
            <div class="demoTable layui-form">
                <div class="layui-input-inline" style="width: 180px;">
    <input type="search" name="id" autocomplete="off" class="layui-input" placeholder=""/>
</div>
<div class="layui-input-inline" style="width: 180px;">
    <input type="search" name="name" autocomplete="off" class="layui-input" placeholder="分类名称"/>
</div>

                <div class="layui-inline fr ml20">
                <span class="layui-btn layui-btn-normal" id="refresh_wrapper">
					<i class="layui-icon">&#xe666;</i>
				</span>
                </div>
                <div class="layui-inline ml20 ">
                <span class="layui-btn search_btn" data-type="reload">
                    <i class="layui-icon">&#xe615;</i>&nbsp;&nbsp;搜索
                </span>
                </div>
                <div class="clear"></div>
            </div>
        </form>
    </blockquote>
    <div class="layui-field-box" id="layer-photos-demo">
        <table class="layui-hide" id="test" lay-filter="demo"></table>
    </div>
    <!--操作-->
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm " lay-event="add"><i class="layui-icon">&#xe608;</i>增加</a>
            <a class="layui-btn layui-btn-sm layui-btn-danger " lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>
            <a class="layui-btn layui-btn-sm layui-btn-primary " lay-event="detail"><i class="layui-icon">&#xe60b;</i>查看</a>
            <a class="layui-btn layui-btn-sm layui-btn-normal " lay-event="update"><i class="layui-icon">&#xe642;</i>编辑</a>
        </div>
    </script>
</div>
<include file="public/footer"/>
<script>
    function add() {
        var index = layer.open({
            type: 2,
            title: '增加',
            //maxmin : true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: "{:url('Classify/classifyadd')}" // iframe的url
        });
        layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layer.full(index);
        })
    }

    function edit(ukid) {
        var url = "{:url('Classify/classifyedit',['id'=>ukid])}";
        url = url.replace('ukid', ukid);
        var index = layer.open({
            type: 2,
            title: '编辑',
            //maxmin : true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: url // iframe的url
        });
        layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layer.full(index);
        })
    }

    function info(ukid) {
        var url = "{:url('Classify/classifyinfo',['id'=>ukid])}";
        url = url.replace('ukid', ukid);
        var index = layer.open({
            type: 2,
            title: '查看',
            //maxmin : true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: url // iframe的url
        });
        layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layer.full(index);
        })
    }

    function del(ukid, index) {
        var url = "{:url('Classify/classifydelete',['id'=>ukid])}";
        url = url.replace('ukid', ukid);
        $.getJSON(url, function (data) {
            layer.close(index);
            if (data.code == "1") {
                layer.msg(data.msg);
                setTimeout(function () {
                    reloadPage(window);
                }, 700);
            } else {
                layer.alert(data.msg, {icon: 2, anim: 6});
            }
        });
    }

    var data1 = null;
    layui.use('table', function () {
        var table = layui.table;
        //工具栏事件
        table.on('toolbar(demo)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            console.log(obj.config.page);
            switch (obj.event) {
                case 'add':
                    add();
                    break;
                case 'update':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length > 1) {
                        layer.msg('只能同时编辑一个');
                    } else {
                        var id = data[0].id;
                        edit(id);
                    }
                    break;
                case 'detail':
                    if (data.length === 0) {
                        layer.msg('请选择一行查看');
                    } else if (data.length > 1) {
                        layer.msg('只能同时查看一个');
                    } else {
                        id = data[0].id;
                        info(id);
                    }
                    break;
                case 'delete':
                    var idarr = [];
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {
                        $.each(data, function (index, value) {
                            idarr.push(value.id);
                        });
                        var idstr = JSON.stringify(idarr);
                        layer.confirm('确认要删除么', function (index) {
                            del(idstr, index)
                        });
                    }
                    break;
            }
        });
        var ins1 = table.render({
            elem: '#test'
            , url: "{:url('Classify/classifylist')}"
            , cellMinWidth: 80
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , page: true
            , cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', title: 'ID', align: 'center', width: 80}, {
                    field: 'ico_image', title: '分类图标路径', align: 'center', templet: function (d) {
                        return '<div><img height="50" src="' + d.ico_image + '" onclick=bigimg("' + d.ico_image + '") ></div>';
                    }
                }, {field: 'name', title: '分类名称', align: 'center'}, {
                    field: 'url',
                    title: '跳转路径',
                    align: 'center'
                }, {field: 'desc', title: '分类描述', align: 'center'}, {
                    field: 'is_delete',
                    title: '删除状态',
                    align: 'center',
                    templet: function(res){
                        if(res.is_delete){
                            return "已删除"
                        }else{
                            return "未删除"
                        }
                    }}
            ]]
            , method: 'post'
            , response: {
                statusName: 'status' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'msg' //状态信息的字段名称，默认：msg
                , countName: 'total' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            }
            , id: 'testReload'
            , skin: 'row'
            , even: true
        });
        //搜索
        $(".search_btn").on("click", function () {
            ins1.reload({
                where: {
                    para: $('form').serialize()
                }
            });
        });
    });
</script>
</body>
</html>